package com.threeti.mecool.core.domain.model.plan.aspects;

import org.codehaus.jackson.annotate.JsonIgnore;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import com.threeti.mecool.core.domain.model.plan.pojo.Task;
import com.threeti.mecool.core.infrastructure.persistence.plan.TaskRepository;

privileged aspect Task_AJ_Domain {
	@Autowired
	@JsonIgnore
	private transient TaskRepository Task.taskRepository;
	
	static TaskRepository Task.taskRepository() {
		return new Task().taskRepository;
	}
	
	public static Task Task.findById(Long id) {
		return Task.taskRepository().findOne(id);
	}
	
	@Transactional
	public void Task.save() {
		if (taskRepository == null) {
			taskRepository = taskRepository();
		}
		taskRepository.save(this);
	}
}
